﻿using ET.Monitor.DAL;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ET.Monitor.Model
{
    public class StringModel
    {
        /// <summary>
        /// stringId组串编号
        /// </summary>
        string unitID = "",
            stringId, pvstringDes, install, sign, MACHINEID;

        double area = 0;
        int transformation = 0;
        DateTime sTime = new DateTime();
        DateTime eTime = new DateTime();
        StringDAL dal = new StringDAL();
        public StringModel(string unitId) { unitID = unitId; }

        public StringModel(string id, string unitId, string stringDes)
        {
            this.stringId = id;
            this.unitID = unitId;
            this.pvstringDes = stringDes;
        }

        public StringModel(string id, string unitId, string stringDes, double area, string install, int transformation, string sign, string MACHINEID)
        {
            this.stringId = id;
            this.unitID = unitId;
            this.pvstringDes = stringDes;
            this.area = area;
            this.install = install;
            this.transformation = transformation;
            this.sign = sign;
            this.MACHINEID = MACHINEID;
        }

        public StringModel(string id, DateTime st, DateTime et)
        {
            unitID = id;
            sTime = st;
            eTime = et;
        }

        int second = 0;
        public StringModel(string id, DateTime st, DateTime et, int second)
        {
            unitID = id;
            sTime = st;
            eTime = et;
            this.second = second;
        }

        #region 获取组串
        DataTable dtString;

        public DataTable DtString
        {
            get
            {
                return dal.GetString(unitID);
            }

            set
            {
                dtString = value;
            }
        }

        #endregion


        #region 电压
        double avgVoltage;

        public double AvgVoltage
        {
            get
            {
                return dal.GetVoltage(unitID, sTime, eTime);
            }

            set
            {
                avgVoltage = value;
            }
        }
        #endregion

        #region 电流
        double avgInverternIacr;

        public double AvgInverternIacr
        {
            get
            {
                return dal.GetInverternIacr(unitID, sTime, eTime);
            }

            set
            {
                avgInverternIacr = value;
            }
        }
        #endregion

        #region 功率
        double avgPower;

        public double AvgPower
        {
            get
            {
                return dal.GetPower(unitID, sTime, eTime);
            }

            set
            {
                avgPower = value;
            }
        }
        #endregion

        #region 组串增删改

        bool addPvString;

        public bool AddPvString
        {
            get
            {
                return dal.SavePVString(stringId, unitID, pvstringDes, area, install, transformation, sign, MACHINEID);
            }

            set
            {
                addPvString = value;
            }
        }

        public bool UpdatePvString
        {
            get
            {
                return dal.UpdatePVString(stringId, pvstringDes, area, install, transformation, sign,MACHINEID);
            }

            set
            {
                updatePvString = value;
            }
        }

        public bool DeletePvString
        {
            get
            {
                return dal.DeletePVString(stringId);
            }

            set
            {
                deletePvString = value;
            }
        }

        public DataTable DtPvStringInfo
        {
            get
            {
                return dal.GetDtStringById(unitID);
            }

            set
            {
                dtPvStringInfo = value;
            }
        }

        bool updatePvString;

        bool deletePvString;

        DataTable dtPvStringInfo;
        /// <summary>
        /// 包括组串本身信息在内的多信息
        /// </summary>
        DataTable dtPvStringInfos;

        public DataTable DtPvStringInfos
        {
            get
            {
                return dal.GetDtStringInfosById(unitID);
            }

            set
            {
                dtPvStringInfos = value;
            }
        }
        #endregion

        #region 实时电流
        double realIcar;

        public double RealIcar
        {
            get
            {
                return dal.GetRealIacr(unitID);
            }

            set
            {
                realIcar = value;
            }
        }
        #endregion

        #region 电流平均值
        double avgIcar;

        public double AvgIcar
        {
            get
            {
                return dal.GetAvgIacr(unitID);
            }

            set
            {
                avgIcar = value;
            }
        }
        #endregion

        #region 所属逆变器ID
        object objUnitId;

        public object ObjUnitId
        {
            get
            {
                return dal.GetInverterId(unitID);
            }

            set
            {
                objUnitId = value;
            }
        }
        #endregion

        #region 组串状态
        int stringState;

        public int StringState
        {
            get
            {
                return dal.GetStringState(unitID);
            }

            set
            {
                stringState = value;
            }
        }

        public int[] StringStateArray
        {
            get
            {
                return dal.GetStringStateArray(unitID);
            }
        }
        #endregion

        #region 实时电压
        double realVacr;

        public double RealVacr
        {
            get
            {
                return dal.GetRealVacr(unitID);
            }

            set
            {
                realVacr = value;
            }
        }
        #endregion

        #region 电站趋势 离散率
        double[][] dispersionRatio;

        public double[][] DispersionRatio
        {
            get { return dal.GetDispersionRatioLine(unitID, sTime, eTime, second); }
            set { dispersionRatio = value; }
        }
        #endregion
    }
}
